import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  let counter = ref([])
  function piniaAddCard(detailData, goods_id) {
    let username = localStorage.getItem('username')
    let pdcard = counter.value.find(item => item.goods.goods_id == goods_id)
    if (pdcard) {
      pdcard.Number++
    }
    else{
      counter.value.push({
        username:username,
        id:Math.floor(Math.random()*10000000),
        Number:1,
        goods:detailData,
        checked:false,
      })
    }
  }

  return {counter,piniaAddCard}
},
  {
    persist: true,
  },
)